package com.atcapp.server.controller;

import com.atcapp.server.dao.StudentDAO;
import com.atcapp.server.dao.TeacherDAO;
import com.atcapp.server.repository.UserStuRepository;
import com.atcapp.server.repository.UserTeaRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RegisterController {
    @Autowired
    private UserStuRepository userStuRepository;
    @Autowired
    private UserTeaRepository userTeaRepository;
     /*
    * 学生注册模块
    * */
    @PostMapping(value = "/Registerstu")
    public StudentDAO userStuAdd(StudentDAO studentDAO){
        if(userStuRepository.findBystudentID(studentDAO.getStudentID())==null) {
        studentDAO.setName(studentDAO.getName());
        studentDAO.setEmail(studentDAO.getEmail());
        studentDAO.setPassword(studentDAO.getPassword());
        studentDAO.setPermission(studentDAO.getPermission());
        studentDAO.setPhonenumber(studentDAO.getPhonenumber());
        studentDAO.setSex(studentDAO.getSex());
        studentDAO.setStudentID(studentDAO.getStudentID());


        return userStuRepository.save(studentDAO);
        }
        return null;
    }
      /*
    * 教师注册模块
    * */
      @PostMapping(value = "/Registertea")
      public TeacherDAO userTeaAdd(TeacherDAO teacherDAO){
          if(userTeaRepository.findByteacherID(teacherDAO.getteacherID())==null) {
              teacherDAO.setName(teacherDAO.getName());
              teacherDAO.setEmail(teacherDAO.getEmail());
              teacherDAO.setPassword(teacherDAO.getPassword());
              teacherDAO.setPermission(teacherDAO.getPermission());
              teacherDAO.setPhonenumber(teacherDAO.getPhonenumber());
              teacherDAO.setSex(teacherDAO.getSex());
              teacherDAO.setteacherID(teacherDAO.getteacherID());


              return userTeaRepository.save(teacherDAO);
          }
          return null;
      }
}
